#!/bin/bash
#-------------------------------------------------------------------------------------------------------------
#该脚本的使用方式为-->[sh startup.sh]
#该脚本可在服务器上的任意目录下执行,不会影响到日志的输出位置等
#-------------------------------------------------------------------------------------------------------------
#颜色设置
#SETCOLOR_SUCCESS="echo -en \\033[1;32m"
#SETCOLOR_FAILURE="echo -en \\033[1;31m"
#SETCOLOR_NORMAL="echo -en \\033[0;39m"

#设定环境变量

source /etc/profile
#ls -t course*.jar
APP_NAME=course

JAR_ZIP_DIR=/opt/qypay/course
JAR_FILE=`cd ${JAR_ZIP_DIR} && ls -t ${APP_NAME}*.jar |head -n 1`

JAVA_OPTS=" -Xloggc:/opt/logs/course_gc.log -server -Xmx1024M -Xms1024M -Xmn256M -XX:MaxMetaspaceSize=320M -XX:MetaspaceSize=128M -XX:+UseConcMarkSweepGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M"
#JAVA_OPTS="${JAVA_OPT} -Xloggc:/opt/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M"
#JAVA_OPTS=""
####获取pid ###
tradePortalPID=0

#### 启动 ######

start(){
        echo  "Starting $APP_NAME ........"
        nohup $JAVA_HOME/bin/java $JAVA_OPTS -jar $JAR_ZIP_DIR/$JAR_FILE --spring.profiles.active=prod   > $JAR_ZIP_DIR/nohup.log &
        sleep 2
        getTradeProtalPID
        if [ $tradePortalPID -ne 0 ]; then
            echo -e THE ${APP_NAME}\(PID=${tradePortalPID}\)  ............."                    \033[32;49;1m [SUCCESS] \033[39;49;0m"
#            echo  "================================================================================================================"
        else
            echo -e THE ${APP_NAME}\(PID=${tradePortalPID}\)  ............."                     \033[31;49;1m [Failed] \033[39;49;0m"
#            echo  "================================================================================================================"
        fi
}
